package com.byit.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.byit.domain.SysRole;
import com.byit.mapper.SysRoleMapper;
import com.byit.service.ISysRoleService;
import com.byit.utils.PageUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 角色表 服务实现类
 * </p>
 *
 * @author wangx
 * @since 2018-12-11
 */
@Service
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements ISysRoleService {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private SysRoleMapper roleMapper;

    @Override
    public List<String> getAuthUserRole(Long userId) {
        return roleMapper.getAuthUserRole(userId);
    }

    @Override
    public void delRoleById(Map<String, Object> params) {
        roleMapper.delRoleById(params);
    }

    @Override
    public Page<JSONObject> selectRoleList(Page<SysRole> pageInfo, Map<String, Object> params) {
        List<JSONObject> list = roleMapper.selectRoleList(pageInfo, params);

        Page<JSONObject> page = PageUtil.transform(pageInfo);

        page.setRecords(list);

        return page;
    }

    @Override
    public Boolean selectRoleByCode(String name) {
        Integer count = roleMapper.selectRoleByCode(name);
        return (count == 0) ? false : true;
    }

    @Override
    public List<JSONObject> getRoleMap(Long companyId) {
        return roleMapper.getRoleMap(companyId);
    }
}
